/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagedBeans;

import SessionBeans.AdministradorDAO;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class mbLoginAdmin {

    private int userID = 0;
    public String username;
    public String password;
    public String warning = "";
    @EJB
    private AdministradorDAO administradorDAO;

    public mbLoginAdmin() {
    }

    public AdministradorDAO getAdministradorDAO() {
        return administradorDAO;
    }
    
    public void lougout() {
        this.userID = 0;
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("/Tienda_asalinero/faces/admin/usuario/login.xhtml");
        } catch (Exception e) {
            System.err.println("Error en la redirección");
        }
    }

    public String mbAcceder() {
        this.userID = administradorDAO.acceder(username, password);
        if (userID > 0) {
            warning = "";
            username = "";
            return "/admin/usuario/accedido";
        } else {
            warning = "Usuario o contraseña mal introducidos.";
            username = "";
            return "/admin/usuario/login";
        }
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String newUsername) {
        this.username = newUsername;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String newPassword) {
        this.password = newPassword;
    }

    public String getWarning() {
        return warning;
    }

    public void setWarning(String warning) {
        this.warning = warning;
    }

    /**
     * @return the userID
     */
    public int getUserID() {
        return userID;
    }

    /**
     * @param userID the userID to set
     */
    public void setUserID(int userID) {
        this.userID = userID;
    }
}
